//
//  NSString+Utils.m
//  UILbrary
//
//  Created by Apple on 2023/3/2.
//  Copyright © 2023 mac. All rights reserved.
//

#import "NSString+Utils.h"

@implementation NSString (Utils)

/// unicode 字符长度 包含汉字与 表情符号
-(NSUInteger)unicodeLength{
        NSUInteger asciiLength = 0;
        NSRange range;
        for(NSInteger i = 0; i < self.length; i += range.length){
                range = [self  rangeOfComposedCharacterSequenceAtIndex:i];
                asciiLength += 1;
            }
        return asciiLength;
}

///  是否合法手机号
- (BOOL)isValidPhoneNumberFormat
{
    NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"^1([3-9])\\d{9}$" options:0 error:nil];
    NSTextCheckingResult *match = [regex firstMatchInString:self options:0 range:NSMakeRange(0, self.length)];
    return match != nil;
}


@end
